import {
  getRules,
  getItemScore,
  getItemCount
} from '@/services/gaoluDiagnose';

const initState = {
  rules: [],
  itemScore:{
    group:[{
      loseRate: 16.76,
      loseScore: 6.2,
      name: "指标检查",
      totalScore: 37,
    }],
    ind:[{
      name:"透气性指数",
      score: 9,
      loseScore:1,
      loseRate: "10%"
    }]
  },
  itemCount:{
    jj:1,
    sf:1,
    mql:1,
    zt:1,
    tslz:1,
    ltlg:1
  },
  itemCountDetail:null
};

const GaoluDiagnose = {
  namespace: 'gaoluDiagnose',
  state: initState,
  effects: {
    //异步方法,应该通常用于前后端交互
    * getRules({payload}, {call, put}) {
      const response = yield call(getRules, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "rules"
      });
    },
    * getItemScore({payload}, {call, put}) {
      const response = yield call(getItemScore, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "itemScore"
      });
    },
    * getItemCount({payload}, {call, put}) {
      const response = yield call(getItemCount, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "itemCount"
      });
    },
    * getItemCountDetail({payload}, {call, put}) {
      const response = yield call(getItemCount, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "itemCountDetail"
      });
    }
  },
  reducers: {
    saveValues(state, {payload, name}) {
      const v = {...state};
      v[name] = payload;
      return v
    },
  },
};
export default GaoluDiagnose;
